package com.chunguang.netty.comon;

import java.util.Date;
import java.util.concurrent.TimeUnit;

import org.springframework.beans.BeanUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.chunguang.netty.domain.RequestData;
import com.chunguang.netty.domain.TransferData;
import com.chunguang.netty.listener.ApplicationFactory;
import com.chunguang.netty.service.RequestDataService;

import io.netty.channel.ChannelFuture;


public class Main {
	static QueueSiglon queue =null;
	@SuppressWarnings("resource")
	public static void main(String[] args) {
		try {
			queue = QueueSiglon.getInstance();
			ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "spring-context.xml" });
			context.start();
			
			RequestDataService service = (RequestDataService) context.getBean("requestDataService");
			System.out.println("start-------------");
		for(int i=0;i< 4;i++){
			System.err.println(i);
			TransferData transferData = new TransferData();
			transferData.setCheckNumber(new Date().getTime()+"aaaaaaaaaagggd====aa"+i);
			transferData.setSync(0);
			service.insert(transferData );
			RequestData requestData2 = new RequestData();
			BeanUtils.copyProperties(transferData, requestData2, new String[]{"sync"});
			queue.put(requestData2);
			
		}
			
			
			
			
		TimeUnit.SECONDS.sleep(1000);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
//
//public static void main(String[] args) {
//	try {
//		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "spring-context.xml" });
//		context.start();
//		Client c = Client.getInstance();
//		ChannelFuture cf = c.getChannelFuture();
//		
//		ApplicationContext context1 = ApplicationFactory.getContext();
//		System.out.println("dddddddd");
//		RequestDataService service = (RequestDataService) context1.getBean("requestDataService");
//		TransferData transferData = new TransferData();
//		transferData.setCheckNumber("aaaaaaaaaaeeaaaagggddddaaaa");
//		transferData.setSync(0);
//		service.insert(transferData );
//		RequestData requestData2 = new RequestData();
//		BeanUtils.copyProperties(transferData, requestData2, new String[]{"sync"});
//		cf.channel().writeAndFlush(requestData2);
//		
//		cf.channel().closeFuture().sync();
//	} catch (Exception e) {
//		e.printStackTrace();
//	}
//}